package com.ce.pms.report.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.ce.pms.occupation.dao.IPerfectItemDispatchDao;
import com.ce.pms.occupation.model.PerfectItemDispatchDO;
import com.ce.pms.occupation.service.IPerfectItemDispatchService;
import com.ce.pms.occupation.vo.PerfectItemDispatchVO;
import com.ce.pms.occupation.vo.PerfectItemRequisitionVO;
import com.ce.pms.report.vo.PerItemDispatchReportVO;
import com.ce.report.entity.CEReportDataSet;
import com.ce.report.exception.CEReportException;
import com.ce.report.service.ICEReportDataSetService;
import com.ce.report.vo.ReportsQueryBaseVo;
import com.ce.util.BlankUtil;
import com.sitechasia.webx.core.utils.base.PopulateUtil;
/**
 * 功能描述: 退伙记录打印功能类
 * <p>版权所有：中企动力
 * <p>未经本公司许可，不得以任何方式复制或使用本程序任何部分
 *
 * @author  胡煦
 * Create on:2008-9-12
 * Edit author: 黄腾飞
 * Edit on:
 * 修改原因：传入参数修改
 */
public class PerItemDispatchReportService implements ICEReportDataSetService{

	public CEReportDataSet getReportDataSet(ReportsQueryBaseVo arg) throws CEReportException {
		PerItemDispatchReportVO queryVO = (PerItemDispatchReportVO) arg;
		PerItemDispatchReportVO dispatchReportVO = this.create(queryVO.getKeyword());

		Set<PerfectItemRequisitionVO>  perfectItemRequisitionVOSet = dispatchReportVO.getPerfectItemRequisitions();
		List<PerfectItemRequisitionVO> perfectItemRequisitionVOList = new ArrayList<PerfectItemRequisitionVO>();
		if(!BlankUtil.isBlank(perfectItemRequisitionVOSet)) {
			perfectItemRequisitionVOList.addAll(perfectItemRequisitionVOSet);
		}
		Map<String, Object> map = new  HashMap<String, Object>();
		map.put("dispatchNumber", dispatchReportVO.getDispatchNumber());
		map.put("contractorInfoName", dispatchReportVO.getContractorInfoName());
		map.put("dispatchDate", dispatchReportVO.getDispatchDate());
		map.put("description", dispatchReportVO.getDescription());

		return new CEReportDataSet(perfectItemRequisitionVOList,map);
	}


	private PerItemDispatchReportVO create(Long perfectItemDispatchId){

		PerItemDispatchReportVO dispatchReportVO = new PerItemDispatchReportVO();
		PerfectItemDispatchDO dispatchDO = perfectItemDispatchDao.findById(perfectItemDispatchId);
		PerfectItemDispatchVO dispatchVO = perfectItemDispatchService.queryperfectItemDispatchVOById(dispatchDO.getKeyword());
		PopulateUtil.populate(dispatchVO, dispatchReportVO);
		return dispatchReportVO;
	}

	private IPerfectItemDispatchDao perfectItemDispatchDao;
	private IPerfectItemDispatchService perfectItemDispatchService;
	/**
	 * @param perfectItemDispatchService the perfectItemDispatchService to set
	 */
	public void setPerfectItemDispatchService(
			IPerfectItemDispatchService perfectItemDispatchService) {
		this.perfectItemDispatchService = perfectItemDispatchService;
	}


	/**
	 * @param perfectItemDispatchDao the perfectItemDispatchDao to set
	 */
	public void setPerfectItemDispatchDao(
			IPerfectItemDispatchDao perfectItemDispatchDao) {
		this.perfectItemDispatchDao = perfectItemDispatchDao;
	}

}
